<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="java.math.BigDecimal"%>
<%@page import="inet.db.tennis.TennisSeason"%>
<%@page import="inet.db.tennis.TennisChampion"%>
<%@page import="inet.db.tennis.TennisChampionPlayer"%>
<%@page import="inet.db.tennis.TennisPlayer"%>
<%@page import="inet.db.tennis.TennisPhase"%>
<jsp:useBean id="tennisChampionPlayerDAO" class="inet.db.tennis.TennisChampionPlayerDAO" scope="session"/>
<jsp:useBean id="tennisChampionDAO" class="inet.db.tennis.TennisChampionDAO" scope="session"/>
<jsp:useBean id="tennisSeasonDAO" class="inet.db.tennis.TennisSeasonDAO" scope="session"/>
<jsp:useBean id="tennisPhaseDAO" class="inet.db.tennis.TennisPhaseDAO" scope="session"/>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>Danh sách các tay vợt trong giải</title>
    <link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/admin/tennis/css/reset.css" media="screen" />
    <link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/admin/tennis/css/text.css" media="screen" />
    <link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/admin/tennis/css/grid.css" media="screen" />
    <link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/admin/tennis/css/layout.css" media="screen" />
    <link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/admin/tennis/css/nav.css" media="screen" />
    <!--[if IE 6]><link rel="stylesheet" type="text/css" href="css/ie6.css" media="screen" /><![endif]-->
    <!--[if IE 7]><link rel="stylesheet" type="text/css" href="css/ie.css" media="screen" /><![endif]-->
    <link href="<%= request.getContextPath() %>/admin/tennis/css/table/demo_page.css" rel="stylesheet" type="text/css" />
    <!-- BEGIN: load jquery -->
    <script src="<%= request.getContextPath() %>/admin/tennis/js/jquery-1.6.4.min.js" type="text/javascript"></script>
    <script type="<%= request.getContextPath() %>/admin/tennis/text/javascript" src="js/jquery-ui/jquery.ui.core.min.js"></script>
    <script src="<%= request.getContextPath() %>/admin/tennis/js/jquery-ui/jquery.ui.widget.min.js" type="text/javascript"></script>
    <script src="<%= request.getContextPath() %>/admin/tennis/js/jquery-ui/jquery.ui.accordion.min.js" type="text/javascript"></script>
    <script src="<%= request.getContextPath() %>/admin/tennis/js/jquery-ui/jquery.effects.core.min.js" type="text/javascript"></script>
    <script src="<%= request.getContextPath() %>/admin/tennis/js/jquery-ui/jquery.effects.slide.min.js" type="text/javascript"></script>
    <script src="<%= request.getContextPath() %>/admin/tennis/js/jquery-ui/jquery.ui.mouse.min.js" type="text/javascript"></script>
    <script src="<%= request.getContextPath() %>/admin/tennis/js/jquery-ui/jquery.ui.sortable.min.js" type="text/javascript"></script>
    <script src="<%= request.getContextPath() %>/admin/tennis/js/table/jquery.dataTables.min.js" type="text/javascript"></script>
    <!-- END: load jquery -->
    <script type="text/javascript" src="<%= request.getContextPath() %>/admin/tennis/js/table/table.js"></script>
    <script src="<%= request.getContextPath() %>/admin/tennis/js/setup.js" type="text/javascript"></script>
    <script type="text/javascript">

        $(document).ready(function () {
            setupLeftMenu();

            var oTable = $('.datatable').dataTable();
            oTable.fnSort( [ [3,'asc'],[2,'asc'] ] );
			setSidebarHeight();


        });
    </script>
    <script type="text/javascript">
    	function f_delete_select_item() {
    		document.formListPlayerChampion.action.value = 'delete_selected';
    		document.formListPlayerChampion.submit();
    	}
    </script>
</head>
<body>
    <div class="container_12">
        <%@ include file="../include/header.jsp" %>
        <% 
        	String sChampionCode = request.getParameter("championCode");
        	if(sChampionCode == null)sChampionCode = "";
        	String sSeasonId = request.getParameter("slbSeason");
        	BigDecimal seasonId = null;
    		if(sSeasonId != null) seasonId = new BigDecimal(sSeasonId);
    		
        	String sPhaseId = request.getParameter("slbPhaseId");
        	BigDecimal phaseId = null;
        	if(sPhaseId != null) phaseId = new BigDecimal(sPhaseId);
        	
        	// Delete selected rows
    		String sAction = request.getParameter("action");
    		if(sAction != null && "delete_selected".equals(sAction)) {
    			String[] selected = request.getParameterValues("chkID");
    			if (selected != null && selected.length > 0) {
		            for (int i = 0; i < selected.length; i++) {
						tennisChampionPlayerDAO.deleteRow(new BigDecimal(selected[i]));
		            }
		        }
    		}
    		
    		TennisChampion currChampion = tennisChampionDAO.getRow(sChampionCode);
    		if(seasonId == null && currChampion != null){
        		seasonId = currChampion.getCurrentSeason();
        	}
    		if(phaseId == null && currChampion != null){
        		phaseId = currChampion.getCurrentPhase();
        	}

        	Vector<TennisChampionPlayer> vTennisChampionPlayer = tennisChampionPlayerDAO.findAll(sChampionCode, seasonId, phaseId );
        %>
        <div class="grid_6">
            <div class="box round first grid">
            	<form name="formListPlayerChampion" method="post">
                	<input type="hidden" name="action"/>
	                <h2>Danh sách các tay vợt trong giải: &nbsp;&nbsp;&nbsp;
	                	<select id="select" name="slbChampion" onchange="window.top.location=formListPlayerChampion.slbChampion.options[formListPlayerChampion.slbChampion.selectedIndex].value;">
	           				<%
	           					Vector<TennisChampion> vTennisChampion = tennisChampionDAO.findChampionRunning();
	           					if( vTennisChampion != null && !vTennisChampion.isEmpty()) {
	           						TennisChampion champion1 = null;
	           						for (Iterator it = vTennisChampion.iterator(); it.hasNext(); ){
	           							champion1 = (TennisChampion)it.next();
	           							if(champion1 == null) continue;
	           				%>
	           				<option <%= champion1.getCode().equals(sChampionCode) ? "selected":"" %> value="?championCode=<%= champion1.getCode() %>"> <%= champion1.getName() %></option>
	           				<%
	           						}
	           					}
	           				%>
	            		</select>
	                	<select id="select" name="slbSeason" onchange="submit();">
	           				<%
	           					Vector<TennisSeason> vTennisSeason = tennisSeasonDAO.findAll(sChampionCode);
	           					if( vTennisSeason != null && !vTennisSeason.isEmpty()) {
	           						TennisSeason season = null;
	           						for (Iterator it = vTennisSeason.iterator(); it.hasNext(); ){
	           							season = (TennisSeason)it.next();
	           							if(season == null) continue;
	           				%>
	           				<option <%= season.getId().equals(seasonId) ? "selected":"" %> value="<%= season.getId() %>"> <%= season.getSeasonName() %></option>
	           				<%
	           						}
	           					}
	           				%>
	            		</select>
	                	<select id="select" name="slbPhaseId" onchange="submit();">
	                		<option value="0"> -Chọn giai đoạn- </option>
	           				<%
	           					Vector<TennisPhase> vTennisPhase = tennisPhaseDAO.findAll(sChampionCode, seasonId);
	           					if( vTennisPhase != null && !vTennisPhase.isEmpty()) {
	           						TennisPhase phase = null;
	           						for (Iterator it = vTennisPhase.iterator(); it.hasNext(); ){
	           							phase = (TennisPhase)it.next();
	           							if(phase == null) continue;
	           				%>
	           				<option <%= phase.getId().equals(phaseId) ? "selected":"" %> value="<%= phase.getId() %>"> <%= phase.getPhaseName() %></option>
	           				<%
	           						}
	           					}
	           				%>
	            		</select>
	                </h2>
	                <div class="block">
	                    <table class="data display datatable" id="example">
							<thead>
								<tr>
									<th style="width: 5%;">&nbsp;</th>
									<th style="width: 25%;">Tên mùa giải</th>
									<th style="width: 20%;">Tên tay vợt</th>
									<th style="width: 20%;">Hạt giống</th>
									<th style="width: 5%;">Sửa</th>
								</tr>
							</thead>
							<tbody>
								<% 
									if(vTennisChampionPlayer != null && !vTennisChampionPlayer.isEmpty()) {
										TennisChampionPlayer championPlayer = null;
										int i = 0;
										String seasonName = "";
										for (Iterator it = vTennisChampionPlayer.iterator(); it.hasNext(); ) {
											championPlayer = (TennisChampionPlayer)it.next();
											if( championPlayer == null ) continue;
								%>
								<tr class="gradeA">
									<td>
										<input type="checkbox" name="chkID" value="<%= championPlayer.getId() %>" />
									</td>
									<td><%= championPlayer.getSeasonName() %></td>
									<td><%= championPlayer.getPlayerName() %></td>
									<td><%= championPlayer.getSeed() != null ? championPlayer.getSeed():"" %></td>
									<td>
										<a href="edit-player-champion.jsp?id=<%= championPlayer.getId() %>">
											<img style="vertical-align: middle;" src="<%= request.getContextPath() %>/admin/tennis/img/cog.png" />
										</a>
									</td>
								</tr>
								<% 
										}
									}
								%>
							</tbody>
						</table>
		                <a href="add-player-champion.jsp?championCode=<%= sChampionCode %>" class="btn-mini btn-black btn-plus" title="Thêm mới"><span></span>Add</a>
		                <a onclick="if(confirm('Bạn có chắc chắn muốn xóa ??? ')){f_delete_select_item();}" class="btn-mini btn-black btn-cross" title="Xóa"><span></span>Delete</a>
	                </div>
               	</form>
            </div>
        </div>
        <div class="clear">
        </div>
    </div>
    <%@ include file="../include/footer.jsp" %>
</body>
</html>